<template>
  <div class="app-container">
    <!-- <span class="title">个人申请与审核</span>
    <el-divider></el-divider> -->
    <div class="filter-container">
      <el-form inline>
        <el-form-item label="项目类型">
          <el-select @change="selectType" placeholder="项目类型" v-model="listQuery.type">
            <el-option v-for="(item,index) in typeList" :key="index" :label="item.name" :value="item.type" />
          </el-select>
        </el-form-item>
        <el-form-item label="所属区县">
          <el-select placeholder="所属区县" v-model="listQuery.district" clearable>
            <el-option v-for="(item,index) in quxianList" :key="index" :label="item.name" :value="item.id" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button @click="changePage()" type="primary">查询</el-button>
          <el-button @click="daochu()" type="primary">导出报表</el-button>
        </el-form-item>
      </el-form>
    </div>

    <el-table v-show="listQuery.type == 1" v-loading="listLoading" :data="list" element-loading-text="加载中" highlight-current-row>
      <el-table-column align="center" type="index" label="序号" width="80"></el-table-column>
      <el-table-column align="center" show-overflow-tooltip prop="distName" label="行政区"></el-table-column>
      <el-table-column align="center" show-overflow-tooltip prop="total" label="总计"></el-table-column>
      <el-table-column align="center" show-overflow-tooltip label="在办项目">
        <el-table-column align="center" show-overflow-tooltip prop="pendingTotal" label="小计"></el-table-column>
        <el-table-column align="center" show-overflow-tooltip prop="pendingTypeAmountDisplay.dpjy" label="地票交易"></el-table-column>
        <el-table-column align="center" show-overflow-tooltip prop="pendingTypeAmountDisplay.zjgg" label="增减挂钩"></el-table-column>
        <el-table-column align="center" show-overflow-tooltip prop="pendingTypeAmountDisplay.cjjx" label="拆旧建新"></el-table-column>
      </el-table-column>
      <el-table-column align="center" show-overflow-tooltip label="已办结项目">
        <el-table-column align="center" show-overflow-tooltip prop="finishedTotal" label="小计"></el-table-column>
        <el-table-column align="center" show-overflow-tooltip prop="finishedTypeAmountDisplay.dpjy" label="地票交易"></el-table-column>
        <el-table-column align="center" show-overflow-tooltip prop="finishedTypeAmountDisplay.zjgg" label="增减挂钩"></el-table-column>
        <el-table-column align="center" show-overflow-tooltip prop="finishedTypeAmountDisplay.cjjx" label="拆旧建新"></el-table-column>
      </el-table-column>
    </el-table>
    <el-table v-show="listQuery.type == 2" v-loading="listLoading" :data="list" element-loading-text="加载中" highlight-current-row>
      <el-table-column align="center" type="index" label="序号" width="80"></el-table-column>
      <el-table-column align="center" show-overflow-tooltip prop="distName" label="行政区"></el-table-column>
      <el-table-column align="center" show-overflow-tooltip prop="total" label="总计"></el-table-column>
      <el-table-column align="center" show-overflow-tooltip label="在办项目">
        <el-table-column align="center" show-overflow-tooltip prop="pendingTotal" label="小计"></el-table-column>
        <el-table-column align="center" show-overflow-tooltip prop="pendingTypeAmountDisplay.ybsjzz" label="一般市级整治"></el-table-column>
        <el-table-column align="center" show-overflow-tooltip prop="pendingTypeAmountDisplay.scjdjs" label="蔬菜基地建设"></el-table-column>
        <el-table-column align="center" show-overflow-tooltip prop="pendingTypeAmountDisplay.sqxgjcstcsd" label="市区县共建城乡统筹试点"></el-table-column>
        <el-table-column align="center" show-overflow-tooltip prop="pendingTypeAmountDisplay.sfp" label="市扶贫"></el-table-column>
        <el-table-column align="center" show-overflow-tooltip prop="pendingTypeAmountDisplay.stnysfq" label="生态农业示范区"></el-table-column>
        <el-table-column align="center" show-overflow-tooltip prop="pendingTypeAmountDisplay.yddb" label="异地代保"></el-table-column>
        <el-table-column align="center" show-overflow-tooltip prop="pendingTypeAmountDisplay.jbntsfq" label="基本农田示范区"></el-table-column>
        <el-table-column align="center" show-overflow-tooltip prop="pendingTypeAmountDisplay.gtzzsd" label="国土整治试点"></el-table-column>
        <el-table-column align="center" show-overflow-tooltip prop="pendingTypeAmountDisplay.bzgyjs" label="标准果园建设"></el-table-column>
      </el-table-column>
      <el-table-column align="center" show-overflow-tooltip label="已办结项目">
        <el-table-column align="center" show-overflow-tooltip prop="finishedTotal" label="小计"></el-table-column>
        <el-table-column align="center" show-overflow-tooltip prop="finishedTypeAmountDisplay.ybsjzz" label="一般市级整治"></el-table-column>
        <el-table-column align="center" show-overflow-tooltip prop="finishedTypeAmountDisplay.scjdjs" label="蔬菜基地建设"></el-table-column>
        <el-table-column align="center" show-overflow-tooltip prop="finishedTypeAmountDisplay.sqxgjcstcsd" label="市区县共建城乡统筹试点"></el-table-column>
        <el-table-column align="center" show-overflow-tooltip prop="finishedTypeAmountDisplay.sfp" label="市扶贫"></el-table-column>
        <el-table-column align="center" show-overflow-tooltip prop="finishedTypeAmountDisplay.stnysfq" label="生态农业示范区"></el-table-column>
        <el-table-column align="center" show-overflow-tooltip prop="finishedTypeAmountDisplay.yddb" label="异地代保"></el-table-column>
        <el-table-column align="center" show-overflow-tooltip prop="finishedTypeAmountDisplay.jbntsfq" label="基本农田示范区"></el-table-column>
        <el-table-column align="center" show-overflow-tooltip prop="finishedTypeAmountDisplay.gtzzsd" label="国土整治试点"></el-table-column>
        <el-table-column align="center" show-overflow-tooltip prop="finishedTypeAmountDisplay.bzgyjs" label="标准果园建设"></el-table-column>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { getMyDownListType,getDistList,projectDistTypeStatistics } from "@/api/tongji";
export default {
  filters: {},
  data() {
    return {
      list: null,
      total: null,
      listLoading: false,
      listQuery: {
        district: '',
        type: 1,
      },
      typeList:[], //项目类型列表
      quxianList:[], //区县列表
    };
  },
  created() {
    this.getTypeList()
    this.getAreaData()
    this.fetchData()
  },
  methods: {
    //导出
    daochu(){
      var a = document.createElement("a");
      var obj = ""
      var checkNullorNot = 0
      var objArr = this.listQuery
      for (var index in objArr) {
        if(objArr[index]!==''&&objArr[index]!=null){
          obj += "&" + index + "=" + objArr[index]
          checkNullorNot++
        }
      }
      if(checkNullorNot != 0){
        obj = obj.substr(1)
        obj = '?' + obj
      }
      console.log(obj,"携带参数")
      a.setAttribute(
        "href",
        this.$https +
          "/renovation/project/export/exportProjectDistTypeStatistics" + obj
      );
      a.click();
    },
    //切换项目类型
    selectType(val){
      this.fetchData()
    },
    //获取所有项目类型
    getTypeList(){
      getMyDownListType().then(res =>{
        var arr = []
        res.data.forEach((v,i)=>{
          if(v.type == 1 || v.type == 2){
            arr.push(v)
          }
        })
        this.typeList = arr
      })
    },
    //获取所有区县
    getAreaData(){
      getDistList().then(res =>{
        this.quxianList = res.data
      })
    },
    fetchData() {
      this.listLoading = true;
      var data={}
      var objArr=this.listQuery
      for (var index in objArr) {
        if(objArr[index]!==''&&objArr[index]!=null){
          data[index]=objArr[index];
        }
      }
      projectDistTypeStatistics(data)
        .then(res => {
          console.log(res)
          this.listLoading = false;
          var arr=[]
          if(this.listQuery.type == 1){
            res.data.forEach(v =>{
              v["pendingTypeAmountDisplay"]={
                dpjy:'',
                zjgg:'',
                cjjx:'',
              }
              v["finishedTypeAmountDisplay"]={
                dpjy:'',
                zjgg:'',
                cjjx:'',
              }
              for(var i in v.pendingTypeAmount){
                for(var j in v.pendingTypeAmountDisplay){
                  if(i == '0' && j == 'dpjy'){
                    v.pendingTypeAmountDisplay[j] = v.pendingTypeAmount[i]
                  }
                  if(i == '1' && j == 'zjgg'){
                    v.pendingTypeAmountDisplay[j] = v.pendingTypeAmount[i]
                  }
                  if(i == '2' && j == 'cjjx'){
                    v.pendingTypeAmountDisplay[j] = v.pendingTypeAmount[i]
                  }
                }
              }
              for(var i in v.finishedTypeAmount){
                for(var j in v.finishedTypeAmountDisplay){
                  if(i == '0' && j == 'dpjy'){
                    v.finishedTypeAmountDisplay[j] = v.finishedTypeAmount[i]
                  }
                  if(i == '1' && j == 'zjgg'){
                    v.finishedTypeAmountDisplay[j] = v.finishedTypeAmount[i]
                  }
                  if(i == '2' && j == 'cjjx'){
                    v.finishedTypeAmountDisplay[j] = v.finishedTypeAmount[i]
                  }
                }
              }
            })
          }else if(this.listQuery.type == 2){
            res.data.forEach(v =>{
              v["pendingTypeAmountDisplay"]={
                ybsjzz:'',
                scjdjs:'',
                sqxgjcstcsd:'',
                sfp:'',
                stnysfq:'',
                yddb:'',
                jbntsfq:'',
                gtzzsd:'',
                bzgyjs:'',
              }
              v["finishedTypeAmountDisplay"]={
                ybsjzz:'',
                scjdjs:'',
                sqxgjcstcsd:'',
                sfp:'',
                stnysfq:'',
                yddb:'',
                jbntsfq:'',
                gtzzsd:'',
                bzgyjs:'',
              }

              for(var i in v.pendingTypeAmount){
                for(var j in v.pendingTypeAmountDisplay){
                  if(i == '0' && j == 'ybsjzz'){
                    v.pendingTypeAmountDisplay[j] = v.pendingTypeAmount[i]
                  }
                  if(i == '1' && j == 'scjdjs'){
                    v.pendingTypeAmountDisplay[j] = v.pendingTypeAmount[i]
                  }
                  if(i == '2' && j == 'sqxgjcstcsd'){
                    v.pendingTypeAmountDisplay[j] = v.pendingTypeAmount[i]
                  }
                  if(i == '3' && j == 'sfp'){
                    v.pendingTypeAmountDisplay[j] = v.pendingTypeAmount[i]
                  }
                  if(i == '4' && j == 'stnysfq'){
                    v.pendingTypeAmountDisplay[j] = v.pendingTypeAmount[i]
                  }
                  if(i == '5' && j == 'yddb'){
                    v.pendingTypeAmountDisplay[j] = v.pendingTypeAmount[i]
                  }
                  if(i == '6' && j == 'jbntsfq'){
                    v.pendingTypeAmountDisplay[j] = v.pendingTypeAmount[i]
                  }
                  if(i == '7' && j == 'gtzzsd'){
                    v.pendingTypeAmountDisplay[j] = v.pendingTypeAmount[i]
                  }
                  if(i == '8' && j == 'bzgyjs'){
                    v.pendingTypeAmountDisplay[j] = v.pendingTypeAmount[i]
                  }
                }
              }

              for(var i in v.finishedTypeAmount){
                for(var j in v.finishedTypeAmountDisplay){
                  if(i == '0' && j == 'ybsjzz'){
                    v.finishedTypeAmountDisplay[j] = v.finishedTypeAmount[i]
                  }
                  if(i == '1' && j == 'scjdjs'){
                    v.finishedTypeAmountDisplay[j] = v.finishedTypeAmount[i]
                  }
                  if(i == '2' && j == 'sqxgjcstcsd'){
                    v.finishedTypeAmountDisplay[j] = v.finishedTypeAmount[i]
                  }
                  if(i == '3' && j == 'sfp'){
                    v.finishedTypeAmountDisplay[j] = v.finishedTypeAmount[i]
                  }
                  if(i == '4' && j == 'stnysfq'){
                    v.finishedTypeAmountDisplay[j] = v.finishedTypeAmount[i]
                  }
                  if(i == '5' && j == 'yddb'){
                    v.finishedTypeAmountDisplay[j] = v.finishedTypeAmount[i]
                  }
                  if(i == '6' && j == 'jbntsfq'){
                    v.finishedTypeAmountDisplay[j] = v.finishedTypeAmount[i]
                  }
                  if(i == '7' && j == 'gtzzsd'){
                    v.finishedTypeAmountDisplay[j] = v.finishedTypeAmount[i]
                  }
                  if(i == '8' && j == 'bzgyjs'){
                    v.finishedTypeAmountDisplay[j] = v.finishedTypeAmount[i]
                  }
                }
              }
            })
          }
          
          this.list = res.data;
        })
        .catch(err => {
          this.listLoading = false;
        });
    },
    changePage(page) {
      this.fetchData();
    }
  }
};
</script>
